﻿<Window x:Class="Core.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:helper="clr-namespace:Helpers;assembly=Helpers"
        Title="{helper:Localize MainCoreTitle}"
        Background="{DynamicResource FondPage}"
        DataContext="{Binding Main,
                              Source={StaticResource Locator}}"
        Icon="/Assets/nentang.ico"
        PreviewKeyDown="MainWindow_OnPreviewKeyDown"
        PreviewKeyUp="MainWindow_OnPreviewKeyUp"
        WindowState="Maximized">

    <Window.Resources>
        <Style x:Key="ButtonDisconnectStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <TextBlock x:Name="textblock">
                            <ContentPresenter />
                        </TextBlock>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="textblock" Property="TextDecorations" Value="Underline" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="White" />
        </Style>
    </Window.Resources>

    <Window.InputBindings>
        <KeyBinding Key="F12"
                    Command="{Binding AssignModeDebugCommand}"
                    Modifiers="Control+Shift" />
        <KeyBinding Key="Escape" Command="{Binding SelectCommand}" />
    </Window.InputBindings>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
            <RowDefinition Height="40" />
        </Grid.RowDefinitions>

        <Grid Background="{DynamicResource BrushHeaderWindow}">
            <Grid Visibility="{Binding IsAuth, Converter={StaticResource BoolToVisibilityWithParamConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!--  Menu  -->
                <Grid Grid.Row="0"
                      Grid.Column="0"
                      Margin="0,0,0,0"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="1" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Button Grid.Column="0"
                            Command="{Binding OpenAccueilCommand}"
                            Style="{StaticResource ButtonAccueil}" />
                    <Line Grid.Column="1"
                          Margin="0,7,0,7"
                          VerticalAlignment="Center"
                          Stretch="Fill"
                          Stroke="#55CCCCCC"
                          StrokeThickness="1"
                          X1="0"
                          X2="0"
                          Y1="0"
                          Y2="1" />
                    
                    <!-- Recherche -->
                    <Grid Grid.Column="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <Border Grid.Column="0"
                                Height="30"
                                Margin="10,0,0,0"
                                VerticalAlignment="Center"
                                Background="{DynamicResource ColorUltraLightThemeBrush}"
                                CornerRadius="{DynamicResource CornerRadiusLeftSize}">
                            <TextBox Width="250"
                                     Margin="5,0,5,0"
                                     VerticalAlignment="Center"
                                     Background="#FFFFFFFF"
                                     BorderThickness="0"
                                     FontSize="16"
                                     KeyUp="SearchOnKeyUp"
                                     Padding="5,0,0,0"
                                     Text="{Binding SearchPattern,
                                                    Mode=TwoWay,
                                                    UpdateSourceTrigger=PropertyChanged}" />
                        </Border>
                        <Button Grid.Column="1"
                                Margin="0,0,0,0"
                                VerticalAlignment="Center"
                                Command="{Binding UnifiedSearchCommand}"
                                Style="{StaticResource ButtonSearch}" />
                        <ToggleButton x:Name="ButtonOptions"
                                      Grid.Column="2"
                                      Margin="0,0,0,0"
                                      VerticalAlignment="Center"
                                      Style="{StaticResource ButtonSearchDetails}" />
                        <Popup x:Name="PART_Popup"
                               AllowsTransparency="True"
                               HorizontalOffset="-300"
                               IsOpen="{Binding Path=IsChecked,
                                                ElementName=ButtonOptions}"
                               Placement="Relative"
                               PlacementTarget="{Binding ElementName=ButtonOptions}"
                               PopupAnimation="Fade"
                               StaysOpen="False"
                               VerticalOffset="30">
                            <Grid Width="320"
                                  Height="190"
                                  Background="{DynamicResource ColorUltraLightThemeBrush}">
                                <Grid Margin="10,20,10,10">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>

                                    <StackPanel Grid.Row="0"
                                                Margin="0,10,0,0"
                                                Orientation="Vertical">
                                        <Label Content="{helper:Localize SearchExtended_LabelForChoiceModule}" />
                                        <ComboBox Margin="5,0,0,0"
                                                  HorizontalAlignment="Stretch"
                                                  DisplayMemberPath="Name"
                                                  ItemsSource="{Binding ModulesForSearch}"
                                                  SelectedItem="{Binding SelectedModuleSearch,
                                                                         Mode=TwoWay}" />
                                    </StackPanel>

                                    <!-- Options de recherche supplémentaires -->
                                    <StackPanel Grid.Row="1" Margin="5,20,0,0" HorizontalAlignment="Stretch" />

                                    <Button Grid.Row="2"
                                            Margin="5,20,0,0"
                                            HorizontalAlignment="Stretch"
                                            Command="{Binding UnifiedSearchCommand}"
                                            Content="{helper:Localize SearchExtended_SearchAction}"
                                            Style="{DynamicResource MetroFlatButtonStevia}" />
                                </Grid>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ListBox Grid.Column="3"
                             Height="52"
                             Margin="15,0,0,0"
                             VerticalAlignment="Center"
                             VerticalContentAlignment="Stretch"
                             ItemsSource="{Binding Menus}"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                             ScrollViewer.VerticalScrollBarVisibility="Disabled"
                             SelectedItem="{Binding SelectedMenu,
                                                    Mode=TwoWay}"
                             Style="{StaticResource ListMenu}" />
                </Grid>

                <!--  Menu parametres, notifications  -->
                <Grid Grid.Column="1" Background="Transparent">
                    <StackPanel Height="50"
                                Margin="0,0,30,0"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Top"
                                Orientation="Horizontal">
                        <StackPanel Margin="15,0,15,0"
                                    VerticalAlignment="Center"
                                    Orientation="Horizontal">
                            <TextBlock Foreground="{DynamicResource ColorTextBarreMenuEtatBrush}" Text="{Binding AccessControlService.CurrentUser, StringFormat={helper:Localize General_ConnectionUser}}" />
                            <Button Margin="10,0,0,0"
                                    Command="{Binding DisconnectCommand}"
                                    Content="{helper:Localize General_Disconnect}"
                                    Style="{StaticResource ButtonAppBar}" />
                            <TextBlock Margin="2,0,0,0"
                                       Foreground="{DynamicResource ColorTextBarreMenuEtatBrush}"
                                       Text=")" />
                        </StackPanel>
                        <Button Margin="15,0,15,0"
                                Command="{Binding OpenCenterNotificationCommand}"
                                Content="{Binding NumberNotification}"
                                Style="{StaticResource ButtonNotification}"
                                Visibility="{Binding IsUseNotification, Converter={StaticResource BoolToVisibilityWithParamConverter}}"/>
                        <Button Margin="15,0,0,0"
                                Command="{Binding OpenParametersCommand}"
                                Content="{helper:Localize ParameterTitle}"
                                Style="{StaticResource ButtonAppBar}" />
                    </StackPanel>
                </Grid>
            </Grid>
        </Grid>

        <!--  Contenu  -->
        <Rectangle Grid.Row="1"
                   Height="15"
                   VerticalAlignment="Top">
            <Rectangle.Fill>
                <LinearGradientBrush MappingMode="RelativeToBoundingBox" Opacity="0.2" StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#FF000000" />
                    <GradientStop Offset="1" Color="{DynamicResource ColorFondPage}" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>

        <ContentControl x:Name="ContentLoaded"
                        Grid.Row="1"
                        Margin="0,0,0,0"
                        Content="{Binding ContentToLoad}" />

        <!--  Barre d'etat  -->
        <Border Grid.Row="2" Background="{DynamicResource BrushHeaderWindow}">
            <Grid Margin="10,0,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!--  Partie Libre  -->
                <ContentControl Grid.Column="0" Content="{Binding ContentFreeBarreEtat}" />

                <!--  Partie Message  -->
                <Grid Grid.Column="1" Margin="10,0,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="20" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <!--  Icône  -->
                    <Viewbox Width="16.000"
                             Height="16.000"
                             VerticalAlignment="Center"
                             Visibility="{Binding Path=Visibility, ElementName=TextBarreEtat,
                                                  Converter={StaticResource StringValueVisibilityConverter}}">
                        <Canvas Width="16.000" Height="16.000">
                            <Canvas>
                                <Path x:Name="IconBarreEtat" Fill="{StaticResource BrushIconBarreMessage}" />
                            </Canvas>
                        </Canvas>
                    </Viewbox>

                    <!--  Message  -->
                    <TextBlock Grid.Column="1"
                               Margin="10,0,0,0"
                               VerticalAlignment="Center"
                               Style="{StaticResource StyleMessageBarreEtat}"
                               x:Name="TextBarreEtat" />
                </Grid>

                <!--  Statut de la connection  -->
                <StackPanel x:Name="StatusDatabaseOffline"
                            Grid.Column="2"
                            Margin="5,0,5,0"
                            VerticalAlignment="Center"
                            Orientation="Horizontal"
                            Visibility="{Binding DatabaseService.Service.IsOffline,
                                                 Converter={StaticResource BoolToVisibilityWithParamConverter}}">
                    <Image Width="24"
                           Height="24"
                           VerticalAlignment="Center"
                           Source="/Assets/DatabaseOffline.png" />
                    <TextBlock Margin="10,0,0,0"
                               VerticalAlignment="Center"
                               Style="{StaticResource StyleMessageBarreEtat}"
                               Text="{helper:Localize Generic_NotificationDatabaseOffline}" />
                </StackPanel>

                <StackPanel Grid.Column="2"
                            Margin="5,0,5,0"
                            VerticalAlignment="Center"
                            Orientation="Horizontal"
                            Visibility="{Binding Path=Visibility,
                                                 ElementName=StatusDatabaseOffline,
                                                 Converter={StaticResource InvertVisibilityConverter}}">
                    <Image Width="24"
                           Height="24"
                           VerticalAlignment="Center"
                           Source="/Assets/DatabaseOnline.png" />
                    <TextBlock Margin="10,0,0,0"
                               VerticalAlignment="Center"
                               Style="{StaticResource StyleMessageBarreEtat}"
                               Text="{helper:Localize Generic_NotificationDatabaseOnline}" />
                </StackPanel>
            </Grid>
        </Border>

        <!--  Pour les "fenetres" filles  -->
        <ContentControl Grid.Row="0"
                        Grid.RowSpan="3"
                        Margin="0,0,0,0"
                        Content="{Binding ContentChildWindow}" />
    </Grid>

</Window>
